import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:share_fit/app/components/back_btn_icon.dart';
import 'package:share_fit/app/controllers/space/setting/setting_unit_logic.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/app/tools/color_const.dart';
import 'package:share_fit/app/ute/uteped_const.dart';
import 'package:share_fit/generated/locales.g.dart';
import 'package:sprintf/sprintf.dart';

class SettingPage extends StatelessWidget {

  final logic = Get.put(SettingLogic());

  @override
  Widget build(BuildContext context) {
    Map appInfo = logic.read(UTEPedConst.keyAppInfo, defaultValue: [], global: true);
    return Scaffold(
      appBar: AppBar(
        title: Text(LocaleKeys.setting.ts, style: TextStyle(fontSize: 54.sp, color: ColorConst.btnFontColor),),
        centerTitle: true,
        leading: BackBtnIcon(onTap: () => Get.back()),
      ),
        body: ListView(
          padding: const EdgeInsets.only(top: 15, bottom: 80),
          children: [
            Container(
              margin: const EdgeInsets.all(15),
              child: Column(
                children: [
                  _buildListTile(LocaleKeys.setting_unit.ts, "", true, false, onTap: () {
                    Get.toNamed('/space/setting/unit');
                  }),
                  const Divider(height: 1,),
                  // _buildListTile(LocaleKeys.setting_time.ts, "", false, false, onTap: () {}),
                  // Divider(height: 1,),
                  // _buildListTile(LocaleKeys.setting_feedback.ts, "", false, false, onTap: () {}),
                  // Divider(height: 1,),
                  _buildListTile(LocaleKeys.setting_private.ts, "", false, false,
                      onTap: () {Get.toNamed('/space/setting/private');}),
                  const Divider(height: 1,),
                  _buildListTile(LocaleKeys.setting_agreement.ts, "", false, false,
                      onTap: () {Get.toNamed('/space/setting/agreement');}),
                  const Divider(height: 1,),
                  _buildListTile(LocaleKeys.setting_about.ts, sprintf("%s.%s", [appInfo['versionName'], appInfo['versionCode']]), false, true,
                      onTap: () {Get.toNamed('/space/setting/about');}),
                  // FutureBuilder<AppInfo>(
                  //   future: InstalledApps.getAppInfo(appInfo['packageName']),
                  //   builder:
                  //       (BuildContext buildContext, AsyncSnapshot<AppInfo> snapshot) {
                  //     return snapshot.connectionState == ConnectionState.done
                  //         ? snapshot.hasData
                  //         ?_buildListTile(LocaleKeys.setting_about.ts, appInfo['versionName'], false, true,
                  //         onTap: () {Get.toNamed('/space/setting/about');})
                  //         : _buildListTile(LocaleKeys.setting_about.ts, '', false, true,
                  //         onTap: () {Get.toNamed('/space/setting/about');})
                  //         : Center();
                  //   },
                  // ),
                  // _buildListTile(LocaleKeys.setting_about.ts, "1.4.32",
                  //     onTap: () {Get.toNamed('/space/setting/about');}),
                ],
              ),
            )
          ],
        )
    );
  }

  Widget _buildListTile(
      String title, String trailing, isFirst, isLast, {onTap}) {

    var borderRadius = BorderRadius.circular(0);
    if (isFirst && !isLast) {
      borderRadius = const BorderRadius.vertical(top: Radius.circular(10));
    } else if (!isFirst && isLast) {
      borderRadius = const BorderRadius.vertical(bottom: Radius.circular(10));
    } else if (isFirst && isLast) {
      borderRadius = BorderRadius.circular(10);
    }
    return Ink(
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: borderRadius,
        ),
        child: InkResponse(
            onTap: onTap,
            splashColor: ColorConst.activeColor,
            borderRadius: borderRadius,
            highlightShape: BoxShape.rectangle,
            highlightColor: ColorConst.activeColor,
            containedInkWell: true,
            child: ListTile(
                contentPadding: EdgeInsets.fromLTRB(62.w, 0, 36.h, 0),
                title: Text(title, style: TextStyle(fontSize: 42.sp, color: ColorConst.btnFontColor)),
                trailing: SizedBox(
                  width: 220.w,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(trailing, style: TextStyle(fontSize: 42.sp, color: ColorConst.btnFontColor,)),
                      Icon(
                        size: 37.w,
                        Icons.arrow_forward_ios,
                      ),
                    ],
                  ),
                ),),
        ));
    // return ListTile(
    //     contentPadding: EdgeInsets.fromLTRB(62.w, 0, 36.h, 0),
    //     title: Text(title, style: TextStyle(fontSize: 42.sp, color: ColorConst.btnFontColor)),
    //     trailing: SizedBox(
    //       width: 174.h,
    //       child: Row(
    //         mainAxisAlignment: MainAxisAlignment.spaceBetween,
    //         children: [
    //           Text(trailing, style: TextStyle(fontSize: 42.sp, color: ColorConst.btnFontColor,)),
    //           Icon(
    //             size: 37.w,
    //             Icons.arrow_forward_ios,
    //           ),
    //         ],
    //       ),
    //     ),
    //     onTap: onTap);
  }

}